package top.lyc829.iot_android.http.interceptor;

import com.blankj.utilcode.util.SPUtils;
import com.xuexiang.xhttp2.interceptor.HttpLoggingInterceptor;

import java.io.IOException;

import okhttp3.Connection;
import okhttp3.Request;
import okhttp3.Response;
import top.lyc829.iot_android.util.Utils;

/**
 * @Author lyc
 * @create 2021-06-18 16:13
 */
public class TokenInterceptor extends HttpLoggingInterceptor {

    public TokenInterceptor(String tag) {
        super(tag);
        setLevel(Level.BODY);
    }

    @Override
    protected void logForRequest(Request request, Connection connection) throws IOException {
        super.logForRequest(request, connection);
    }

    @Override
    protected Response logForResponse(Response response, long tookMs) {

        String token= response.header("token", "-1");
        Utils.Sout("token:--------------" + token);
        if (token != null && !token.equals("-1")) {
            SPUtils.getInstance().put("token", token);
        }

        return super.logForResponse(response, tookMs);
    }
}
